/*
 * @Author: huangtianyang 916072572@qq.com
 * @Date: 2023-04-21 10:32:37
 * @LastEditors: huangtianyang
 * @LastEditTime: 2023-07-28 11:56:00
 * @FilePath: \cxl-h5\src\pages\personalCenter\invoice\detailed\index.ts
 */
import { invoiceDetailed } from '@/apis/invoice'

import { storage } from '@/store/sessionStorage'
import { BasicData } from '@/utils/basicData'
import { reactive, ref } from 'vue'
import { useRoute } from 'vue-router'

export default class InvoiceDetailed extends BasicData {
    //刷新状态
    refreshLoading = ref(false)
    //发票状态 false 开票中 true 开票成功
    invoiceStatus = ref(false)
    //发票数量
    invoiceCount = ref(0)
    //订单数量
    orderNumber = ref(0)
    //发票金额
    invoiceMoney = ref(0.0)
    //发票抬头
    invoiceTitle = ref(0.0)
    //公司税号
    CORPORATION_TAX = ref(0.0)
    //申请时间
    invoiceApplyTime = ref(0.0)
    //邮箱地址
    invoiceEmail = ref(0.0)
    //手机号码
    invoicePhone = ref(0.0)
    //发票内容
    invoiceContent = reactive([
        { name: '发票金额', value: '' },
        { name: '发票抬头', value: '' },
        { name: '公司税号', value: '' },
        { name: '申请时间', value: '' },
        { name: '邮箱地址', value: '' },
        { name: '手机号码', value: '' }
    ])
    detailedOrderList: any[] = []
    route: any
    //订单id
    id = ref('')
    constructor() {
        super()
        this.route = useRoute()
        const type = this.route.query.type
        this.id.value = this.route.query.id
        //type = 1 开票中， 2 开票成功
        this.invoiceStatus.value = Number(type) === 1 ? false : true
        this.getData()
    }
    //获取订单详情数据
    getData = () => {
        invoiceDetailed(this.id.value).then(res => {
            if (res.data.value === 200) {
                this.invoiceContent[0].value = res.data.data.amount
                this.invoiceContent[1].value = res.data.data.invoiceCompany
                this.invoiceContent[2].value = res.data.data.taxNumber
                this.invoiceContent[3].value = res.data.data.createTime
                this.invoiceContent[4].value = res.data.data.email
                this.invoiceContent[5].value = res.data.data.phone
                this.orderNumber.value = res.data.data.reportOrderInfoVos.length
                this.detailedOrderList.length = 0
                this.detailedOrderList.push(...res.data.data.reportOrderInfoVos)
                storage.set('invoiceDetailedOrder', JSON.stringify(this.detailedOrderList))
            }
        })
    }
    //打开发票订单列表
    onOpenInvoiceOrder = () => {
        this.router.push('/invoice/order')
    }
}
